/**
 * 业务模块基类
 */
define(["jquery"], function($) {

	'use strict';	
	
	
	/**
	 * 根据传入参数构造业务类原型基础数据,参数传递有两种方式，建议采用第一种构造方式，第二种方式保留为向下兼容
	 * 
	 * @param _options.doc	当前完整的dom页面对象
	 * @param _options.rootId 业务模块页面根节点dom元素
	 * @param _options.panelSelector	业务信息上方panel(提示信息内容)
	 * @param _options.subSystemCode	子系统名称代码
	 * @param _options.moduleCode 业务模块代码名称
	 *  
	 * 
	 * @returns rootPath,pageDoc,pageHeight,gridHeight
	 * @return rootPath 系统发布web目录
	 * @return pageDoc
	 * @return pageWidth
	 * @return pageHeight
	 * @return panelHeight
	 * @return gridHeight
	 * @return mainPageUrl
	 * @return editPageUrl
	 * @return delUrl
	 * @return queryUrl
	 * @return saveUrl
	 */
	function bizBase(_options) {
        var _doc,_rootId,_panelSelector,_subSystemCode,_moduleCode
    	
        if(_options!=null){
			_doc=_options.doc!=null?_options.doc:null
			_rootId = _options.rootId!=null?_options.rootId:null
			_panelSelector = _options.panelSelector!=null?_options.panelSelector:null
			_subSystemCode = _options.subSystemCode!=null?_options.subSystemCode:null
			_moduleCode = _options.moduleCode!=null?_options.moduleCode:null
			
			this.rootPath = "/" + _doc.location.pathname.split('/')[1];
			        
	        this.pageDoc = $(_doc).find('#'+_rootId);
	        this.bizCode = _moduleCode;
	        this.rootid = _rootId;
	        var _currentTab = $('#centerTabs');
	        if (_currentTab.length > 0){
	        	_currentTab = $('#centerTabs').tabs('getSelected')
	        	this.pageWidth = $(_currentTab).width() 
	        	this.pageHeight = $(_currentTab).height() -45
	         }
	        
	        this.panelHeight = $(this.pageDoc).find('#'+_panelSelector).height()
	        
	        this.gridHeight = this.pageHeight - this.panelHeight 
	        
	        if((_subSystemCode!=null)&&(_moduleCode!=null)){
	        	var pathPre = this.rootPath + '/'+_moduleCode
	        	
	        	this.basePath = this.rootPath + '/'+ _subSystemCode +'/'+_moduleCode
		        this.mainPageUrl=pathPre + 'MainPage.action'
		        this.eidtPageUrl=pathPre + 'EditPage.action'
		        
		        //query service page
		        this.queryMainPageUrl=pathPre + "/query/mainPage.action";
		        this.queryEditPageUrl=pathPre + "/query/editPage.action";
		        
		        //query service url
		        this.queryListUrl=pathPre + "/query/getListDomain.action";
		        this.queryTreeUrl=pathPre + "/query/getTreeList.action";
		        this.queryOneUrl=pathPre + "/query/getOne.action";
		        this.exportExcelUrl=pathPre + "/query/exportExcel.action";
		        
		        
				this.delUrl	= pathPre + '/del.action' 
				this.saveUrl = pathPre + '/save.action'
				this.queryUrl = pathPre + '/getList.action'
				this.treeUrl = pathPre + '/getTree.action'
				this.queryDomainUrl = pathPre + '/getListDomain.action'
				
				//审核url
				this.auditPermitUrl	= pathPre + '/auditPermit.action' 
				this.auditSubmitUrl = pathPre + '/auditSubmit.action'
				this.auditDeniedUrl = pathPre + '/auditDenied.action'
				
				this.auditListUrl	= pathPre + '/auditList.action' 
				this.auditOneUrl = pathPre + '/auditOne.action'
				
				
				//流程相关url 
				var flowPathPre = this.rootPath +  '/'+_moduleCode
				this.flowEidtPageUrl=flowPathPre + '/editPage.action'
				this.flowQueryUrl = flowPathPre + '/flowListDomain.action'
				this.flowFinishedQueryUrl = flowPathPre + '/getFinishedListDomain.action'
				this.flowSaveUrl = flowPathPre + '/flowSave.action'
				this.flowDel = flowPathPre + '/flowDel.action'
				this.flowHistoricUrl=flowPathPre +  '/query/flowHistoricsListDomain.action'
				this.flowSignUrl= flowPathPre + '/flowSign.action'
				this.flowTaskCompleteUrl=flowPathPre +'/flowTaskComplete.action'
				
				this.flowSendbackUrl = flowPathPre +'/flowSendback.action'
	       }
	       		
	   }
    	
    }   
    
    var private_method = {
    	/**
    	 * json参数格式构造函数
    	 * @param _options.doc	当前完整的dom页面对象
		 * @param _options.rootId 业务模块页面根节点dom元素
		 * @param _options.panelSelector	业务信息上方panel(提示信息内容)
		 * @param _options.subSystemCode	子系统名称代码
		 * @param _options.moduleCode 业务模块代码名称
    	 */
    	constractorJson:function(_options){
    		var doc,rootId,panelSelector,subSystemCode,moduleCode
    		doc=_options.doc
    		rootId = _options.rootId
    		panelSelector = _options.panelSelector
    		subSystemCode = _options.subSystemCode!=null?_options.subSystemCode:null
    		moduleCode = _options.moduleCode!=null?_options.moduleCode:null
    		private_method.constractorParams(doc,rootId,panelSelector,subSystemCode,moduleCode)
    	},
    	
    	/**
    	 *  数组参数构造函数
    	 *  ：
		 * @param doc	当前完整的dom页面对象
		 * @param rootId 业务模块页面根节点dom元素
		 * @param panelSelector	业务信息上方panel(提示信息内容)
		 * @param subSystemCode	子系统名称代码
		 * @param moduleCode 业务模块代码名称
    	 */
    	constractorParams:function(doc,rootId,panelSelector,subSystemCode,moduleCode){
    		if(rootId!=null){
				this.rootPath = "/" + doc.location.pathname.split('/')[1];
		        
		        this.pageDoc = $(doc).find('#'+rootId);
		        var _currentTab = $('#centerTabs').tabs('getSelected');
		        this.pageWidth = $(_currentTab).width() 
		        this.pageHeight = $(_currentTab).height() -45
		         
		        this.panelHeight = $(this.pageDoc).find('#'+panelSelector).height()
		        
		        this.gridHeight = this.pageHeight - this.panelHeight 
		        if((subSystemCode!=null)&&(moduleCode!=null)){
		        	var pathPre = '/'+ this.rootPath + '/'+ subSystemCode +'/'+moduleCode
			        this.mainPageUrl=pathPre + 'MainPage.action'
			        this.eidtPageUrl=pathPre + 'EditPage.action'
					this.delUrl	= pathPre + 'Del.action' 
					this.saveUrl = pathPre + 'Save.action'				
					this.queryUrl = pathPre + 'ListDomain.action'			
		       }else{
		       		
		       }
	    	}
    	}
    }
    
    bizBase.prototype = {
    	getPageWidth:function(){
    		return this.pageWidth
    	},
    	getPageHeight:function(){
    		return this.pageHeight
    	},
    	getPageDoc:function(){
    		return this.pageDoc
    	},
    	getRootPath:function(){
    		return this.rootPath
    	},
    	getGridHeight:function(){
    		return this.gridHeight
    	}
    }
    
    

    return bizBase;
});
